<html>
<head>
  <title>Type - Test Cases</title>
</head>
<body>

<script src="../lib/type.js"></script>
<script type="text/javascript">
if (!(window.Type && window.Type.Version)) {

document.writeln("Type doesn't exist. Build with Ruby/Rake.");

} else {

function Foobar() {};

document.write('<pre style="font-size:11px;">');

document.writeln('================================================================================');
document.writeln('~~~~~~~~~~~~~~~~~~~~~~~~ Enhanced Data-Type Distinction ~~~~~~~~~~~~~~~~~~~~~~~~');
document.writeln('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ CGU Stand-Alone Type ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
document.writeln('================================================================================');
document.writeln('');

document.writeln('Version : ', Type.Version);
document.writeln('');

document.writeln('');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('========================================================================== TYPES');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('');

document.writeln("Type.types() => ", Type.types().join('\n             => '));
document.writeln('');

document.writeln('');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('============================================================================ GET');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('');

document.writeln('typeof(undefined)          => ', typeof(undefined));
document.writeln('Type.get(undefined)        => ', Type.get(undefined));
document.writeln('');
document.writeln('typeof(null)               => ', typeof(null));
document.writeln('Type.get(null)             => ', Type.get(null));
document.writeln('');
document.writeln('typeof([2,3])              => ', typeof([2,3]));
document.writeln('typeof(new Array(2,3))     => ', typeof(new Array(2,3)));
document.writeln('Type.get([2,3])            => ', Type.get([2,3]));
document.writeln('Type.get(new Array(2,3))   => ', Type.get(new Array(2,3)));
document.writeln('');
document.writeln('typeof(true)               => ', typeof(true));
document.writeln('typeof(new Boolean())      => ', typeof(new Boolean()));
document.writeln('Type.get(true)             => ', Type.get(true));
document.writeln('Type.get(new Boolean())    => ', Type.get(new Boolean()));
document.writeln('');
document.writeln('typeof(new Date())         => ', typeof(new Date()));
document.writeln('Type.get(new Date())       => ', Type.get(new Date()));
document.writeln('');
document.writeln('typeof(new Error())        => ', typeof(new Error()));
document.writeln('Type.get(new Error())      => ', Type.get(new Error()));
document.writeln('Type.get(new TypeError())  => ', Type.get(new TypeError()));
document.writeln('Type.get(new URIError())   => ', Type.get(new URIError()));
document.writeln('');
document.writeln('typeof(function(){})       => ', typeof(function(){}));
document.writeln('typeof(new Function())     => ', typeof(new Function()));
document.writeln('Type.get(function(){})     => ', Type.get(function(){}));
document.writeln('Type.get(new Function())   => ', Type.get(new Function()));
document.writeln('');
document.writeln('typeof(24.42)              => ', typeof(24.42));
document.writeln('typeof(new Number())       => ', typeof(new Number()));
document.writeln('Type.get(24.42)            => ', Type.get(24.42));
document.writeln('Type.get(new Number())     => ', Type.get(new Number()));
document.writeln('');
document.writeln('typeof({})                 => ', typeof({}));
document.writeln('typeof(new Object())       => ', typeof(new Object()));
document.writeln('Type.get({})               => ', Type.get({}));
document.writeln('Type.get(new Object())     => ', Type.get(new Object()));
document.writeln('');
document.writeln('typeof(/./i)               => ', typeof(/./i));
document.writeln('typeof(new RegExp())       => ', typeof(new RegExp()));
document.writeln('Type.get(/./i)             => ', Type.get(/./i));
document.writeln('Type.get(new RegExp())     => ', Type.get(new RegExp()));
document.writeln('');
document.writeln('typeof("abc")              => ', typeof('abc'));
document.writeln('typeof(new String())       => ', typeof(new String()));
document.writeln('Type.get("abc")            => ', Type.get('abc'));
document.writeln('Type.get(new String())     => ', Type.get(new String()));
document.writeln('');
document.writeln('');
document.writeln('typeof(new Foobar())       => ', typeof(new Foobar()));
document.writeln('Type.get(new Foobar())     => ', Type.get(new Foobar()));
document.writeln('');

document.writeln('');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('========================================================================== CLONE');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('');

document.writeln('Type.clone(undefined)        => ', Type.clone(undefined));
document.writeln('Type.clone(null)             => ', Type.clone(null));
document.writeln('');
document.writeln('Type.clone([2,3])            => ', Type.clone([2,3]));
document.writeln('Type.clone(new Array(2,3))   => ', Type.clone(new Array(2,3)));
document.writeln('');
document.writeln('Type.clone(true)             => ', Type.clone(true));
document.writeln('Type.clone(new Boolean())    => ', Type.clone(new Boolean()));
document.writeln('');
document.writeln('Type.clone(new Date())       => ', Type.clone(new Date()));
document.writeln('');
document.writeln('Type.clone(new Error())      => ', Type.clone(new Error()));
document.writeln('Type.clone(new TypeError())  => ', Type.clone(new TypeError()));
document.writeln('Type.clone(new URIError())   => ', Type.clone(new URIError()));
document.writeln('');
document.writeln('Type.clone(function(){})     => ', Type.clone(function(){}).toString().replace(/\s+/g, ' '));
document.writeln('Type.clone(new Function())   => ', Type.clone(new Function()).toString().replace(/\s+/g, ' '));
document.writeln('');
document.writeln('Type.clone(24.42)            => ', Type.clone(24.42));
document.writeln('Type.clone(new Number())     => ', Type.clone(new Number()));
document.writeln('');
document.writeln('Type.clone({})               => ', Type.clone({}));
document.writeln('Type.clone(new Object())     => ', Type.clone(new Object()));
document.writeln('');
document.writeln('Type.clone(/./i)             => ', Type.clone(/./i));
document.writeln('Type.clone(new RegExp())     => ', Type.clone(new RegExp()));
document.writeln('');
document.writeln('Type.clone("abc")            => ', Type.clone('abc'));
document.writeln('Type.clone(new String("a"))  => ', Type.clone(new String('a')));
document.writeln('');
document.writeln('');
document.writeln('Type.clone(new Foobar())     => ', Type.clone(new Foobar()));
document.writeln('');
document.writeln('');
var a = [1, 2, 3, 4, 5, 6];
document.writeln('var a = [1, 2, 3, 4, 5, 6];  => ', a);
document.writeln('Type.clone(a).splice(0, 1);  => ', Type.clone(a).splice(0, 1));
document.writeln('a                            => ', a);
document.writeln('a.splice(0, 1);              => ', a.splice(0, 1));
document.writeln('a                            => ', a);
document.writeln('');
document.writeln('');
document.writeln('Type.clone(');
document.writeln('  (function () { // outer');
document.writeln('    var T = 1;');
document.writeln('    return function () { // inner');
document.writeln('      return T;');
document.writeln('    };');
document.writeln('  }).call() // outer');
document.writeln(').call() // inner            => ', Type.clone((function(){var T=1; return function(){return T;};})())());
document.writeln('');

document.writeln('');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('=========================================================================== IS-A');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('');

document.writeln('Type.is_a([], Array)    => ', Type.is_a([], Array));
document.writeln('Type.is_a([], "array")  => ', Type.is_a([], "array"));
document.writeln('Type.is_a([], Object)   => ', Type.is_a([], Object));
document.writeln('');
document.writeln('');
document.writeln(' // boolean, number, and string primitives are promoted');
document.writeln('');
document.writeln('Type.is_a(false, Boolean)  => ', Type.is_a(false, Boolean));
document.writeln('Type.is_a(12.34, Number)   => ', Type.is_a(12.34, Number));
document.writeln('Type.is_a("foo", String)   => ', Type.is_a("foo", String));
document.writeln('');
document.writeln('false instanceof Boolean   => ', false instanceof Boolean);
document.writeln('12.34 instanceof Number    => ', 12.34 instanceof Number);
document.writeln('"foo" instanceof String    => ', "foo" instanceof String);
document.writeln('');
document.writeln('');
document.writeln(' // comparing constructors to Object will always return true');
document.writeln('');
document.writeln('Type.is_a(new String(), Object)   => ', Type.is_a(new String(), Object));
document.writeln('Type.is_a("new String", Object)   => ', Type.is_a("new String", Object));
document.writeln('');
document.writeln('');
document.writeln(' // is_a allows comparison to 2 primitives: null and undefined');
document.writeln('');
document.writeln('Type.is_a(undefined, undefined)  => ', Type.is_a(undefined, undefined));
document.writeln('Type.is_a(null, null)            => ', Type.is_a(null, null));
document.writeln('');
document.writeln('');
document.writeln(' // supports non-standard constructors');
document.writeln('');
document.writeln('Type.is_a(new Foobar(), Foobar)    => ', Type.is_a(new Foobar(), Foobar));
document.writeln('Type.is_a(new Foobar(), Object)    => ', Type.is_a(new Foobar(), Object));
document.writeln('Type.is_a(new Foobar(), "object")  => ', Type.is_a(new Foobar(), "object"));
document.writeln('');

document.writeln('');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('=========================================================================== ISOF');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('');

document.writeln('Type.isof([], "array", "string")  => ', Type.isof([], "array", "string"));
document.writeln('Type.isof({}, "array", "string")  => ', Type.isof({}, "array", "string"));
document.writeln('Type.isof("", "array", "string")  => ', Type.isof('', "array", "string"));
document.writeln('');
document.writeln('Type.isof("", "array", String)    => ', Type.isof('', "array", String));
document.writeln('Type.isof("", Array, "string")    => ', Type.isof('', Array, "string"));
document.writeln('Type.isof([], Array, "string")    => ', Type.isof([], Array, "string"));
document.writeln('Type.isof({}, Array, String)      => ', Type.isof({}, Array, String));
document.writeln('');
document.writeln('Type.isof(new String(), Object)   => ', Type.isof(new String(), Object));
document.writeln('Type.isof("new String", Object)   => ', Type.isof("new String", Object));
document.writeln('');

document.writeln('');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('========================================================================== LIMIT');
document.writeln('--------------------------------------------------------------------------------');
document.writeln('');

document.writeln(' // limit is a shortcut for using isof and clone');
document.writeln('');
document.writeln('Type.limit([0,1], "array", "string")  => ', Type.limit([0,1], 'array', 'string'));
document.writeln('Type.limit({0:1}, "array", "string")  => ', Type.limit({0:1}, 'array', 'string'));
document.writeln('Type.limit("0.1", "array", "string")  => ', Type.limit('0.1', 'array', 'string'));
document.writeln('');
document.writeln('Type.limit([0,1], Array, String)      => ', Type.limit([0,1], Array, String));
document.writeln('Type.limit({0:1}, Array, "string")    => ', Type.limit({0:1}, Array, "string"));
document.writeln('');
document.writeln('Type.limit(new String(), Object, String)     => ', Type.limit(new String(), Object, String));
document.writeln('Type.limit("new String", Object, String)     => ', Type.limit("new String", Object, String));
document.writeln('');
document.writeln('');
document.writeln(' // default return is undefined (or, no matches)');
document.writeln(' // so, trying to limit with undefined can be misleading');
document.writeln('');
document.writeln('Type.limit()                          => ', Type.limit());
document.writeln('Type.limit(undefined)                 => ', Type.limit(undefined));
document.writeln('Type.limit(undefined, "undefined")    => ', Type.limit(undefined, 'undefined'));
document.writeln('Type.limit(null,      "object")       => ', Type.limit(null, 'object'));
document.writeln('');

document.write('</pre>');

}
</script>

</body>
</html>
